#!/usr/local/bin/bash
# automated script to keep trying to rerun service if down
echo "AppWiki Rebooter beginning"
cd /www/httpd/sites
for file in $(ps auxww | grep ruby | egrep -v grep | awk '{print $2}' )
do
  echo "found and killed ruby thread"
  kill $file
done
echo "now sleeping for three seconds to let ports free up"
sleep 3 
echo "now rebooting"
for file in $(ps auxww | grep ruby | egrep -v grep | awk '{print $2}' )
do
  echo "found and killed ruby thread more assertively"
  kill -9 $file
done
echo "now sleeping for three seconds to let ports free up"
sleep 3 
echo "now rebooting"
/usr/local/bin/ruby >& log appwiki/base/base_mongrel.rb &
for file in $(ps auxww | grep ruby | egrep -v grep | awk '{print $2}' )
do
  echo "Found running ruby thread - good"
done
